<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
   <head>
	 <meta charset="utf-8">
	 <meta http-equiv="X-UA-Compatible" content="IE=edge">
	 <meta name="viewport" content="width=device-width, initial-scale=1">
   </head>
   <body>
	<div class="modal-content">
	  <div class="modal-header">
	    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	    <h4 class="modal-title" id="myModalLabel"><c:if test="${type==1}">新增</c:if><c:if test="${type==2}">编辑</c:if></h4>
	  </div>
	  <div class="modal-body">
	
	    <form id="objectForm" class="form-horizontal" method="post">
	    
	      <div class="form-group">
	      	<input type="hidden" name="id" value="${wyUser.id}"/>
	        <input type="hidden" class="typeCode" value="${type}"/>
	        <label for="name" class="col-sm-2 control-label"><span style="color:red;"> * </span>名称</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="name" name="name" value="${wyUser.name}">
	        </div>
	      </div> 
	      
	      <div class="form-group">
	        <label for="code" class="col-sm-2 control-label"><span style="color:red;"> * </span>编码</label>
	        <div class="col-sm-6">
	          <input type="text" class="form-control" id="code" name="code" value="${wyUser.code}">
	        </div>
	      </div>
		<div class="form-group">
			<label for="content" class="col-sm-2 control-label">绑定账户</label>
			<div class="col-sm-10">
				<c:if test="${type==2}"><input type="hidden" id="wyAccountEdit" value="${wyUser.wyAccount.id}"></c:if>
				<select class="form-control combox" id="wyAccount"
					name="wyAccount[id]" data-live-search="true">
					<c:forEach items="${wyAccountList}" var="wyAccount">
						<option value="${wyAccount.id}">${wyAccount.name}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="form-group">
	        <label for="code" class="col-sm-2 control-label"><span style="color:red;"> * </span>电话号码</label>
	        <div class="col-sm-6">
	          <input type="number" class="form-control" id="telephone" name="telephone" value="${wyUser.telephone}">
	        </div>
	      </div>
		<div class="form-group">
			<label for="content" class="col-sm-2 control-label">性别</label>
			<c:if test="${type==2}"><input type="hidden" id="sexEdit" value="${wyUser.sex}"></c:if>
			<div class="col-sm-6">
				<select class="form-control combox" id="sex"
					name="sex" data-live-search="true">
						<option value="F">女</option>
						<option value="M">男</option>
				</select>
			</div>
		</div>
		</form>
	  </div>
	  <div class="modal-footer">
	  <div class="form-group">
	    <button type="button" class="btn btn-info btn-white btn-round" onclick="objectSubmit();"> <i class="glyphicon glyphicon-ok bigger-125"></i> 确认</button>
	    <button type="button" class="btn btn-default btn-white btn-round" data-dismiss="modal"><i class="glyphicon glyphicon-remove bigger-125"></i> 取消</button>
	  </div>
	  </div>
	</div>
	
	<script>
	 var path = "<%=path%>";
	 $(function(){
		//编辑状态下显示已保存的项目
   	   if($(".typeCode").val()==2){
   		   var wyAccount = $("#wyAccountEdit").val();
	       $('#wyAccount').select2({width:'270px'}).val(wyAccount).trigger("change");
	       
	       $('#sex').select2().val($("#sexEdit").val()).trigger("change");
   	   }
	 });
 	 function objectSubmit(){  
 	 	var url= null;
 	 	var type = $('.typeCode').val();
 	 	if($("#wyAccount").val()==""){
 	 		$("#wyAccount").removeAttr("name");
 	 	}
		if(type==1){//添加实体
			url = path + "/wyUserController/new";
		}else{//编辑实体
			url = path + "/wyUserController/edit";
		}
     	$.ajax({
		  type: "post",
		  url: url,
		  async:false,
		  data: JSON.stringify($('#objectForm').serializeObject()),
		  dataType: "json",
		  contentType:"application/json",  
		  success: function(result){
		         if(result.status){        	 
		        		$.toast({
		        		    text: result.message,
		        		    hideAfter : 1500,  
		        		    stack : 1,  
		        		    showHideTransition: 'slide',
		        		    icon: 'success',
		        		    textAlign : 'center',
		        		    position : 'top-right'
		        		});
		        	   $('#objectForm').parents('.modal').modal('hide');
		        	   $table.bootstrapTable('refresh');
		         }else{
		        	 $.toast({
		        		    text: result.message,
		        		    hideAfter : 1500,  
		        		    stack : 1,  
		        		    showHideTransition: 'slide',
		        		    icon: 'error',
		        		    textAlign : 'center',
		        		    position : 'top-right'
		        		});
		         }
		  }
         });
      } 
	</script>
	</body>
</html>
